package com.arrays;

public class RemoveDuplicatesfromSortedArray0124_26 {
    public int removeDuplicates(int[] nums) {
        /**
         * 快慢指针
         *
         * 初始：i = 0 ，j = 1；分别指向第一、二元素
         *    比较对象 nums[i] == nums[j]
         *   一直将j覆盖到i，前提是j不越界 且 i j 不相等。相等的话，就找下一个不等的j
         *
         */
        int slow = 0, fast = 1;
        while (fast < nums.length) {
            while (nums[fast] == nums[slow]){
                fast++;
                if(fast == nums.length) return slow+1;
            }
            slow++;
            nums[slow] = nums[fast];
            fast++;
        }
        return slow+1;
    }
}
